package com.wyb.moto.common.exception;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wyb.moto.common.exception.AppException;
import com.wyb.moto.common.exception.Result;

@ControllerAdvice
public class GlobalExceptionHandler {
	@ExceptionHandler(Throwable.class)
	@ResponseBody
	public Result handler(Throwable e) {
		String errorMsg = "500 Internal Error";
		if (e instanceof AppException) {
			errorMsg = e.getMessage();
			Result.ok(errorMsg);
		}
		return Result.Error500(errorMsg);
	}

}
